/**
 * @program: LeetCode
 * @description: LeetCode : 724.寻找数组的中心下标
 * @author: WXY
 * @create: 2023-02-07 09:32
 * @Version 1.0
 **/
public class Num724_pivotIndex {
    public static int pivotIndex(int[] arr) {
        int sum = 0;
        int[] array = new int[arr.length];
        array[0] = arr[0];
        for (int i = 1; i < arr.length; i++) {
            array[i] += array[i - 1] + arr[i];
        }
        if (array[arr.length - 1] - array[0] == 0) {
            return 0;
        }
        for (int i = 1; i < arr.length; i++) {
            if ((array[arr.length - 1] - array[i]) == (array[i - 1])) {
                return i;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        int[] arr = {-1,-1,1,1,0,0};
        int index = pivotIndex(arr);
        System.out.println(index);
    }
}
